typedef struct _MESSAGE_FIFO
{
 	BYTE		IndexHead;
	BYTE		Count;
	KEY_EVENT	Buf[MAX_FIFO_DEPTH];

} MESSAGE_FIFO;

MESSAGE_FIFO MsgFifos[MSG_FIFO_COUNT];

BOOL MessageSend(BYTE MsgFifoIndex, BYTE event)							
{	
	MESSAGE_FIFO* pMsgFifo = &MsgFifos[MsgFifoIndex]; 

	if(pMsgFifo->Count >= MAX_FIFO_DEPTH)		
	{
		return FALSE;
	}	
	pMsgFifo->Buf[(pMsgFifo->IndexHead + (pMsgFifo->Count++)) % MAX_FIFO_DEPTH] = event;
	return TRUE;
}

BYTE MessageGet(BYTE MsgFifoIndex)							
{
	KEY_EVENT event = MSG_NONE;
	MESSAGE_FIFO* pMsgFifo = &MsgFifos[MsgFifoIndex];

	if(pMsgFifo->Count)			
	{
		event = pMsgFifo->Buf[pMsgFifo->IndexHead];
		pMsgFifo->IndexHead = (pMsgFifo->IndexHead + 1) % MAX_FIFO_DEPTH;
		pMsgFifo->Count--;
	}				
	return event;
}
